package com.zzyl.serve.controller.member;

import java.util.List;

import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.serve.domain.Elder;
import com.zzyl.serve.domain.ElderInfo;
import com.zzyl.serve.dto.FamilyMemberRequestDto;
import com.zzyl.serve.dto.UserLoginRequestDto;
import com.zzyl.serve.vo.IndexDataVo;
import com.zzyl.serve.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.serve.service.IFamilyMemberService;

/**
 * 老人家属Controller
 *
 * @author itheima
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属相关接口")
@Slf4j
public class FamilyMemberController extends BaseController {
/*1.5和1.6*/
    @Autowired
    private IFamilyMemberService familyMemberService;




    /**
     * 小程序端 用户登录
     */
    @PostMapping("/login")
    @ApiOperation("小程序端 用户登录")
    public R<LoginVo> login(@RequestBody UserLoginRequestDto dto) {

        LoginVo vo = familyMemberService.login(dto);


        return R.ok(vo);
    }

    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public R<String> add(@RequestBody FamilyMemberRequestDto dto) {
        log.info("绑定家人:{}", dto);
        familyMemberService.addFamilyMember(dto);
        return R.ok();
    }
    /**
     * 1.5 按天统计查询指标数据
     * 接口地址:/member/user/queryDeviceDataListByDay
     * 请求方式:GET
     * */
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public IndexDataVo queryDeviceDataListByDay(
            @RequestParam String functionId,
            @RequestParam Long startTime,
            @RequestParam Long endTime,
            @RequestParam String iotId
    ){
        IndexDataVo result = familyMemberService.queryDeviceDataListByDay(functionId, startTime, endTime, iotId);
        return result;
    }



    /**
     * 1.6 按周统计查询指标数据
     * */
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public IndexDataVo queryDeviceDataListByWeek(){
        IndexDataVo result = familyMemberService.queryDeviceDataListByWeek();
        return result;
    }















    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public R<List<Elder>> my() {
        return R.ok(familyMemberService.selectMyFamilyMemberList());
    }

    /*
    * 1.3 查看家人列表（分页查询）
接口地址:/member/user/list-by-page
请求方式:GET
请求参数:pageNum,pageSize
    * */
    @GetMapping("/list-by-page")
    @ApiOperation("查看家人列表（分页查询）")
    public R<List<ElderInfo>> listByPage(String pageNum, String pageSize) {
        List<ElderInfo> info = familyMemberService.listByPage(pageNum, pageSize);
        return R.ok(info);
    }

    /*
    1.4 查询健康数据
    接口地址:/member/user/QueryDevicePropertyStatus
    请求方式:POST
    请求示例:
    {
     "deviceName": "",
     "productKey": ""
    }
    接口地址:/member/user/queryServiceProperties/{iotId}    （新小程序，用这个）
    请求方式:GET
    请求示例: get  "/member/user/queryServiceProperties/67d14b75aa00d1579d_watch003"
    * */
    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("查询健康数据")
    public AjaxResult queryServiceProperties(@PathVariable("iotId") String iotId) {
        AjaxResult ajaxResult = familyMemberService.queryServiceProperties(iotId);
        return ajaxResult;
    }
    /*"/member/user/QueryDevicePropertyStatus"*/
    /*
    * @GetMapping("/queryServiceProperties/{iotId}")
@ApiOperation("查询设备上报数据")
@ApiImplicitParams({
        @ApiImplicitParam(name = "iotId", value = "物联网设备id", required = true, dataTypeClass = String.class)
})
public AjaxResult queryServiceProperties(@PathVariable("iotId") String iotId) {
    AjaxResult ajaxResult = deviceService.queryServiceProperties(iotId);
    return ajaxResult;
}
    * */

}
